package hu.codeguide.xml;

import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * @author David Csejtei, CodeGuide Team, http://codeguide.hu
 * @version 1.0
 */

public class RssHandler extends DefaultHandler {
   
   // Store the items of the RSS channel.
   private List<RssItem> rssItems; 
    
   // Used to reference item while parsing
   private RssItem currentItem;

   // Parsing checker
   private boolean parsingTitle;
   private boolean parsingLink;
   
   // Buffer
   private StringBuffer buffer;
   
   public RssHandler() {
        super();
        rssItems = new ArrayList<RssItem>();
        buffer = new StringBuffer();
   }
	
   public List<RssItem> getRssItems() {
        return rssItems;
   }
   
   @Override
   public void startElement(String uri, String localName, String NodeName, Attributes attributes) throws SAXException {
        if(localName.equalsIgnoreCase("TITLE")) {
            parsingTitle = true;
        }
   }
   
   @Override
   public void endElement(String uri, String localName, String qName) throws SAXException {
       if(buffer != null) {
           Log.e("RSSRESULT2",buffer.toString());
           buffer.setLength(0);
           parsingTitle = false;
       }
   }
   
   @Override
   public void characters(char[] ch, int start, int length) throws SAXException {
       if(parsingTitle) {
           if (buffer!=null) {
                buffer.append(new String(ch, start, length));
           }
       }
   }
    
}
